//
//  AccountManager.m
//  suRead
//
//  Created by 李 诗洋 on 15/11/15.
//  Copyright © 2015年 bao. All rights reserved.
//

#import "AccountManager.h"

#define Account_UserDefaults    [NSUserDefaults standardUserDefaults]
static NSString *kUserDefaultsUserName          = @"kUserDefaultsUserName";
static NSString *kUserDefaultsNickName          = @"kUserDefaultsNickName";
static NSString *kUserDefaultsUserId          = @"kUserDefaultsUserId";
static NSString *kUserDefaultsUserEmail          = @"kUserDefaultsUserEmail";
static NSString *kUserDefaultsUserCode          = @"kUserDefaultsUserCode";
static NSString *kUserDefaultsIsLogined         = @"kUserdefaultsIsLogined";
static NSString *kUserDefaultsUserPhone          = @"kUserDefaultsUserPhone";
static NSString *kUserDefaultsUserImage         = @"kUserDefaultsUserImage";
static NSString *kUserDefaultsUserPonint          = @"kUserDefaultsUserPonint";
static NSString *kUserDefaultsUserMemberLevel          = @"kUserDefaultsUserMemberLevel";
static NSString *kUserDefaultsIsSinaBinding     = @"kUserDefaultsIsSinaBinding";
static NSString *kUserDefaultsIsWechatBinding   = @"kUserDefaultsIsWechatBinding";
static NSString *kUserDefaultsIsQQBinding       = @"kUserDefaultsIsQQBinding";
static NSString *kUserDefaultsEliminate       = @"kUserDefaultsEliminate";

static NSString *kUserDefaultsUCT      = @"kUserDefaultsUCT";
static NSString *kUserDefaultsEncrypt      = @"kUserDefaultsEncrypt";
static NSString *kUserDefaultsUserTags      = @"kUserDefaultsUserTags";
static NSString *kUserDefaultsIsShowViewCount = @"kUserDefaultsIsShowViewCount";
static NSString *kUserDefaultsIp = @"kUserDefaultsIp";


@implementation AccountManager

+ (instancetype)sharedAccountManager
{
    static AccountManager *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedAccountManagerInstance = [self new];
    });
    return sharedAccountManagerInstance;
}

- (BOOL)f_isLogined
{
    NSNumber *login = [Account_UserDefaults objectForKey:kUserDefaultsIsLogined];
    
    if (!login || !login.intValue) return NO;
    else return YES;
}

- (void)setF_isLogined:(BOOL)f_isLogined
{
    if (f_isLogined) {
        [Account_UserDefaults setObject:@1 forKey:kUserDefaultsIsLogined];
    }
    else
    {
        [Account_UserDefaults setObject:@0 forKey:kUserDefaultsIsLogined];
    }
    [Account_UserDefaults synchronize];
}

- (NSString *)f_authCode
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUCT] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUCT];
}

- (void)setF_authCode:(NSString *)f_authCode
{
    [Account_UserDefaults setObject:f_authCode forKey:kUserDefaultsUCT];
}

- (NSString *)f_userName
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserName] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserName];
}
- (void)setF_userName:(NSString *)f_userName
{
    [Account_UserDefaults setObject:f_userName forKey:kUserDefaultsUserName];
}

- (NSString *)f_nickname
{
    return [Account_UserDefaults objectForKey:kUserDefaultsNickName] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsNickName];
}
- (void)setF_nickname:(NSString *)f_nickname
{
    [Account_UserDefaults setObject:f_nickname forKey:kUserDefaultsNickName];
}



- (NSString *)f_uid
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserId] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserId];
}
- (void)setF_uid:(NSString *)f_uid
{
    [Account_UserDefaults setObject:f_uid forKey:kUserDefaultsUserId];
}

- (NSString *)f_email
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserEmail] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserEmail];
}
- (void)setF_email:(NSString *)f_email
{
    [Account_UserDefaults setObject:f_email forKey:kUserDefaultsUserEmail];
}

- (NSString *)f_usercode
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserCode] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserCode];
}
- (void)setF_usercode:(NSString *)f_usercode
{
    [Account_UserDefaults setObject:f_usercode forKey:kUserDefaultsUserCode];
}

- (NSString *)f_phone_num
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserPhone] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserPhone];
}
- (void)setF_phone_num:(NSString *)f_phone_num
{
    [Account_UserDefaults setObject:f_phone_num forKey:kUserDefaultsUserPhone];
}
- (NSString *)f_user_img
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserImage] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserImage];
}
- (void)setF_user_img:(NSString *)f_user_img
{
    [Account_UserDefaults setObject:f_user_img forKey:kUserDefaultsUserImage];
}
- (NSString *)f_point
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserPonint] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserPonint];
}
- (void)setF_point:(NSString *)f_point
{
    [Account_UserDefaults setObject:f_point forKey:kUserDefaultsUserPonint];
}
- (NSString *)f_member_level
{
    return [Account_UserDefaults objectForKey:kUserDefaultsUserMemberLevel] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsUserMemberLevel];
}
- (void)setF_member_level:(NSString *)f_member_level
{
    [Account_UserDefaults setObject:f_member_level forKey:kUserDefaultsUserMemberLevel];
}

- (BOOL)f_isSinaBinding
{
    NSNumber *login = [Account_UserDefaults objectForKey:kUserDefaultsIsSinaBinding];
    
    if (!login || !login.intValue) return NO;
    else return YES;
}

- (void)setF_isSinaBinding:(BOOL)f_isSinaBinding
{
    if (f_isSinaBinding) {
        [Account_UserDefaults setObject:@1 forKey:kUserDefaultsIsSinaBinding];
    }
    else
    {
        [Account_UserDefaults setObject:@0 forKey:kUserDefaultsIsSinaBinding];
    }
}

- (BOOL)f_isWechatBinding
{
    NSNumber *login = [Account_UserDefaults objectForKey:kUserDefaultsIsWechatBinding];
    
    if (!login || !login.intValue) return NO;
    else return YES;
}

- (void)setF_isWechatBinding:(BOOL)f_isWechatBinding
{
    if (f_isWechatBinding) {
        [Account_UserDefaults setObject:@1 forKey:kUserDefaultsIsWechatBinding];
    }
    else
    {
        [Account_UserDefaults setObject:@0 forKey:kUserDefaultsIsWechatBinding];
    }
}

- (BOOL)f_isQQBinding
{
    NSNumber *login = [Account_UserDefaults objectForKey:kUserDefaultsIsQQBinding];
    
    if (!login || !login.intValue) return NO;
    else return YES;
}

- (void)setF_isQQBinding:(BOOL)f_isQQBinding
{
    if (f_isQQBinding) {
        [Account_UserDefaults setObject:@1 forKey:kUserDefaultsIsQQBinding];
    }
    else
    {
        [Account_UserDefaults setObject:@0 forKey:kUserDefaultsIsQQBinding];
    }
}

- (NSString *)f_eliminate
{
    return [Account_UserDefaults objectForKey:kUserDefaultsEliminate] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsEliminate];
}
- (void)setF_eliminate:(NSString *)f_eliminate
{
    [Account_UserDefaults setObject:f_eliminate forKey:kUserDefaultsEliminate];
}

- (NSString *)f_encrypt
{
    return [Account_UserDefaults objectForKey:kUserDefaultsEncrypt] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsEncrypt];
}

- (void)setF_encrypt:(NSString *)f_encrypt
{
    [Account_UserDefaults setObject:f_encrypt forKey:kUserDefaultsEncrypt];
}

- (NSArray *)f_userTags {
    NSData *arrayData = [Account_UserDefaults  objectForKey:kUserDefaultsUserTags];
    NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:arrayData];
    return array;
}

- (void)setF_userTags:(NSArray *)f_userTags {
    NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:f_userTags];
    [Account_UserDefaults setObject:arrayData forKey:kUserDefaultsUserTags];
    [Account_UserDefaults synchronize];
}

- (BOOL)f_isShowViewCount {
    NSNumber *isShow = [Account_UserDefaults objectForKey:kUserDefaultsIsShowViewCount];
    if (!isShow || !isShow.intValue) return NO;
    else return YES;
}

- (void)setF_isShowViewCount:(BOOL)f_isShowViewCount {
    if (f_isShowViewCount) {
        [Account_UserDefaults setObject:@1 forKey:kUserDefaultsIsShowViewCount];
    }
    else {
        [Account_UserDefaults setObject:@0 forKey:kUserDefaultsIsShowViewCount];
    }
}

- (NSString *)f_ip
{
    return [Account_UserDefaults objectForKey:kUserDefaultsIp] == nil ? @"" : [Account_UserDefaults objectForKey:kUserDefaultsIp];
}

- (void)setF_ip:(NSString *)f_ip
{
    [Account_UserDefaults setObject:f_ip forKey:kUserDefaultsIp];
}

@end
